F2='DRUG_ENT'
F8='DISP_ENT'
STORE 0 TO PL4,PL5,PL6,PL7,PL8,PL11
do while pl7<>2 .AND. LASTKEY()<>27
   set colo to w/b
   @ 4,1 CLEA TO 23,78
   DO BOXT WITH 4,3,"INVENTORY ADJUSTMENT",'N+','BG',.T.,.T.
   DO INVAX
   CNT=0
   KODE=SPACE(4)
   kunci=space(5)
   do boxe with 11,3,'Enter Initial of Key Name : ','KUNCI','N','BG','W+','N',5,.T.,.T.
   if lastkey()=27
      set colo to bg+/b,w+/n
*      RESTSCREEN(0,0,24,79,LAY1)
      loop
   endif
   if pl11=1
      do GETDRUG
   else
      do GETDISP
   ENDIF
   IF CNT=0 .or. lastkey()=27
      set colo to bg+/b,w+/n
      LOOP
   ENDIF
   SET COLO TO BG+/B,W+/N
   @ 8,1 CLEAR TO 23,78
   SET INDE TO &DR&F1
*   DO BOXE WITH 4,36,'CODE OF '+APPS+' :','KODE','GR+','R','W+','N',5,.T.,.T.
   SEEK KODE
   IF EOF()
      DO BOX2 WITH 12,3,'NO ITEM WITH THIS CODE NUMBER ... DO YOU WANT TO :','RETRY','CANCEL','GR+','R','W+','N',PL8,.T.,.T.
      IF PL8=2 .OR. LASTKEY()=27
         RETURN
      ENDIF
      LOOP
   ENDIF
   DO INVAR
   SEL=ALLTRIM(SELL_UNIT)
   BUY=ALLTRIM(BUY_UNIT)
   LBUY=LEN(BUY)
   RAT=BUY_SELL_R
   NRAT=ALLTRIM(TRANS(RAT,'9,999'))
   NBUY=ALLTRIM(TRANS(ST_ACT_BUY,'9,999'))
   NSEL=ALLTRIM(TRANS(ST_ACT_SEL,'9,999'))
   NACT=(ST_ACT_BUY*BUY_SELL_R)+ST_ACT_SEL
   DO INVAL
   DO BOX2 WITH 20,3,'DO YOU WANT TO :',"Confirm","Cancel",'GR+','R','W+','N',PL5,.T.,.T.
   SET COLOR TO BG/B
   @ 20,1 CLEA TO 23,78
   DO CASE
      CASE LASTKEY()=27
         RETURN
      CASE PL5=2
         LOOP
      CASE PL5=1
         DO CASE
            CASE RIGHT(BUY,1)='X' .OR. RIGHT(BUY,1)='S'
               DO BOXT WITH 12,1,"Quantity in store, as per permanent inventory : "+NBUY+' '+BUY+'ES','W+','B',.F.,.F.
            CASE RIGHT(BUY,1)<>'X' .AND. RIGHT(BUY,1)<>'S'
               DO BOXT WITH 12,1,"Quantity in store, as per permanent inventory : "+NBUY+' '+BUY+'S','W+','B',.F.,.F.
            OTHER
               DO BOXT WITH 12,1,"Quantity in store, as per permanent inventory : "+NBUY+' '+BUY,'W+','B',.F.,.F.
         ENDCASE
         IF RAT>1
            DO CASE
               CASE RIGHT(SEL,1)='X' .OR. RIGHT(SEL,1)='S'
                  DO BOXT WITH 14,28,"And : "+NSEL+' '+SEL+'ES','W+','B',.F.,.F.
               CASE RIGHT(SEL,1)<>'X' .AND. RIGHT(SEL,1)<>'S'
                  DO BOXT WITH 14,28,"And : "+NSEL+' '+SEL+'S','W+','B',.F.,.F.
               OTHER
                  DO BOXT WITH 14,28,"And : "+NSEL+' '+SEL,'W+','B',.F.,.F.
            ENDCASE
         ENDIF
*         STORE 0 TO BNUM,SNUM
         bnum=st_act_buy
         snum=st_act_sell
         DO BOXNI WITH 16,1,"PHYSICAL BALANCE, STOCK TAKING ("+BUY+") :",'BNUM','9,999','GR+','B','W+','N','10000','0',.F.,.F.
         IF RAT<>1
            DO BOXNI WITH 16,LBUY+46,"And ("+SEL+") :",'SNUM','9,999','GR+','B','W+','N','10000','0',.F.,.F.
         ENDIF
         DO BOX2 WITH 20,3,'DO YOU WANT TO :',"Confirm","Cancel",'GR+','R','W+','N',PL6,.T.,.T.
         DO CASE
            CASE PL6=2
               LOOP
            CASE PL6=1
               BVAL=BNUM*ST_AV_PR_B
               SVAL=SNUM*ST_AV_PR_S
               TOTVAL=BVAL+SVAL
               TOTSEL=(BNUM*RAT)+SNUM

               IF NACT<TOTSEL
                  DIFR=TOTSEL-NACT
                  DIFRB=INT(DIFR/RAT)
                  DIFRS=DIFR-(DIFRB*RAT)
                  NOPE='+'
               ELSE
                  DIFR=NACT-TOTSEL
                  DIFRB=INT(DIFR/RAT)
                  DIFRS=DIFR-(DIFRB*RAT)
                  NOPE='-'
               ENDIF


               IF REC_LOCK(0)
                  REPL ST_ACT_BUY WITH BNUM,st_bom_buy with bnum,ST_ACT_SEL WITH SNUM,st_bom_sel with snum
                  REPL ST_ACT_TOT WITH TOTSEL
                  IF TOTSEL=0
                     REPL ST_AV_PR_B WITH 0,ST_AV_PR_S WITH 0
                  ELSE
                     REPL ST_AV_PR_S WITH TOTVAL/TOTSEL,ST_AV_PR_B WITH ST_AV_PR_S*RAT
                  ENDIF
               ENDIF
               UNLOCK
*****

      IF PL11=1
         SELE 2
         IF FIL_LOCK(0)
            APPEND BLANK
         ENDIF
         IF REC_LOCK(0)
            REPL ENTRY_DATE WITH DATE(),DRUG_CODE WITH A->DRUG_CODE
            REPL DRUG_NAME WITH A->DRUG_NAME,DRUG_TYPE WITH A->DRUG_TYPE,DRUG_QANT WITH A->DRUG_QANT,DRUG_UNIT WITH A->DRUG_UNIT
            REPL BUY_UNIT  WITH A->BUY_UNIT,ENT_QANT  WITH DIFRB,ENT_QSEL WITH DIFRS,OPERATOR WITH NOPE
            REPL SELL_UNIT  WITH A->SELL_UNIT
         ENDIF
         UNLOCK
      ELSE
         SELE 2
         IF FIL_LOCK(0)
            APPEND BLANK
         ENDIF
         IF REC_LOCK(0)
            REPL ENTRY_DATE WITH DATE(),DISP_CODE WITH A->DISP_CODE
            REPL DISP_NAME WITH A->DISP_NAME,DISP_TYPE WITH A->DISP_TYPE,DISP_QANT WITH A->DISP_QANT,DISP_UNIT WITH A->DISP_UNIT
            REPL BUY_UNIT  WITH A->BUY_UNIT,ENT_QANT  WITH DIFRB,ENT_QSEL WITH DIFRS,OPERATOR WITH NOPE
            REPL SELL_UNIT  WITH A->SELL_UNIT
         ENDIF
         UNLOCK
      ENDIF
*****

               DO BOX2 WITH 20,3,'DO YOU WANT TO MODIFY ANOTHER ITEM :',"YES","NO",'GR+','R','W+','N',PL7,.T.,.T.
               IF PL7=2
                  CLOSE DATA
                  CLOSE INDEX
                  RETURN
               ENDIF
         ENDCASE
   ENDCASE
ENDDO